package fem2;

import java.util.ArrayList;
import java.util.Map;

import org.junit.Test;

import fem2.element.StructuralElement;
import fem2.enu.State;
import fem2.material.StVenantKirchhoffMM;
import fem2.mesh_and_topology.IntegrationPointIndexer;
import fem2.mesh_and_topology.SphereSpatialCriteria;
import fem2.pre_and_post.PatchMeshGenerator;

public class QuadTreeTest extends AbstractStructuralStaticDemo {

	@Override
	public Mesh createMesh() {
		MeshGenerator mg = new PatchMeshGenerator(6, 6, 0, 0, 1, 1);
		return mg.getMesh(2);
	}

	@Override
	public Model createConditions(Model m) {
		return m;
	}

	@Override
	public MaterialModel createMaterial(Model m) {
		return new StVenantKirchhoffMM(0, 0, 0, 0, State.PLANE_STRESS);
	}

	@Override
	public Element createElement(MeshPart mp, MaterialModel mm) {
		return new StructuralElement(mp, mm);
	}

	@Test
	public void test1() {
		Model m = createModel();

		IntegrationPointIndexer idx = new IntegrationPointIndexer(m.getMesh());

		for (int i = 0; i < m.countElements(); i++) {
			idx.index(m.getElement(i));
		}

		Map<Element, ArrayList<Integer>> list = idx.queryRange(new SphereSpatialCriteria(2.5, 2.5,
				1));

		for (Element e : list.keySet()) {
			ArrayList<Integer> gps = list.get(e);
			Debugger.watch("Element: " + e.getId());
			Debugger.watch(gps);
			for (int i : gps) {
				Debugger.watch(e.getMeshPart().XAt(e.getIntegrationPoint(i)));
			}
		}
	}

}
